package com.xidian.zhiancloud.service.ypp.messageCenter.untreated;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xidian.zhiancloud.dao.UntreatedMapper;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.exception.CustomizeException;
import com.xidian.zhiancloud.model.Information;
import com.xidian.zhiancloud.model.Notice;
import com.xidian.zhiancloud.model.Untreated;
import com.xidian.zhiancloud.model.UntreatedExample;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UntreatedService {
    @Autowired
    private UntreatedMapper untreatedMapper;

    public List<Untreated> getById(String status) {
        UntreatedExample untreatedExample = new UntreatedExample();
        UntreatedExample.Criteria criteria = untreatedExample.createCriteria();
        criteria.andStatusEqualTo(status);
        List<Untreated> untreatedList = untreatedMapper.selectByExample(untreatedExample);
        if (untreatedList == null) {
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
        return untreatedList;
    }

    public void updateByIds(List<Untreated> untreatedList) {
        for (Untreated untreated:untreatedList){
            Untreated untreated1 = new Untreated();
            BeanUtils.copyProperties(untreated,untreated1);
            untreated1.setStatus("1");
            int result = untreatedMapper.updateByPrimaryKey(untreated1);
            if (result == 0) {
                throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
            }
        }
    }

    public Object getInformation(Long id) {
        Untreated untreated = untreatedMapper.selectByPrimaryKey(id);
        if (untreated == null){
            throw new CustomizeException(GeneralResponseEnums.SYSTEM_ERROR);
        }
        
        if(untreated.getStatus().equals("0")) {
        	Untreated untreated1 = new Untreated();
            untreated1.setStatus("1");
            untreated1.setId(id);
            int result = untreatedMapper.updateByPrimaryKeySelective(untreated1);
        }
       
        return untreated;
    }

	public Page<Untreated> getUntreatedList(Untreated info) {
		// TODO Auto-generated method stub
		PageHelper.startPage(info.getPageNum(), info.getPageSize());
		Page<Untreated> pagedata =untreatedMapper.getUntreatedList(info);
		
		return pagedata;
	}

	public void updateUntreatedByIds(Long[] ids) {
		// TODO Auto-generated method stub
		untreatedMapper.updateUntreatedByIds(ids);
	}

	public void insertInfo(Notice info) {
		// TODO Auto-generated method stub
		untreatedMapper.insertInfo(info);
	}
}
